package final_curso;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Random;

import javax.swing.JPanel;

public class CpanelBolita extends JPanel {
	private static int[] X;	
	private static int[] Y;	
	public static int[] Vy;
	public static int[] Vx;
	public static int[] diam;	
	private static Color[] col;
	private static Graphics2D[] gra;	
	private static int n=35;
	private static Random rnd;

	public CpanelBolita(){
		super();
		this.setVisible(true);
		
		this.setBackground(new Color(180,80,90));
		asignar();
		
				
	}
	private void asignar() {

		gra=new Graphics2D[n];
		col=new Color[n];
		X=new int[n];
		Y=new int[n];
		Vx=new int[n];
		Vy=new int[n];
		diam=new int[n];
		rnd = new Random();
		
		for(int i=0;i<n;i++){
		col[i]=new Color(rnd.nextInt(255),rnd.nextInt(255),rnd.nextInt(255));
		X[i]=rnd.nextInt(120)+1;
		Y[i]=rnd.nextInt(180)+1;
		Vx[i]=rnd.nextInt(5)+1;
		Vy[i]=rnd.nextInt(5)+1;
		diam[i]=rnd.nextInt(11)+20;

		}
		
		
	}
	public void moverBolita(){		
		for (int i=0;i<n;i++){
			if (X[i] >  this.getWidth() - diam[i] )
				Vx[i]=Vx[i]*-1;				
			if (X[i]<0)			
				Vx[i]=Vx[i]*-1;				
			if (Y[i] > this.getHeight()- diam[i])			
				Vy[i]=Vy[i]*-1;			
			if (Y[i]<0)			
				Vy[i]=Vy[i]*-1;			
			
			X[i]+=Vx[i];		
			Y[i]+=Vy[i];		
		}
	}

public void paint(Graphics g){
		
		super.paint(g);
		
		for (int i=0;i<n;i++){
			gra[i]=(Graphics2D)g;
			gra[i].setColor(col[i]);			
			gra[i].fillOval(X[i],Y[i],diam[i],diam[i]);	
			}		
				
		}
	
	
}
